package com.ch.base.factory;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.ch.base.dao.SysSqlLogInfoWrapper;
import com.opensymphony.xwork2.ActionContext;

public class SysUseLogInfoFactory {
	public static void setLogInformation() throws Exception {
//		ActionContext actionContext = ActionContext.getContext();
//		HttpServletRequest request=  (HttpServletRequest)actionContext.get(ServletActionContext. HTTP_REQUEST ); 
//		HttpSession session = (HttpSession) actionContext.getSession();

		/*
		 * 以上寫法弱點掃描會不過, 改寫資訊請看
		 * http://blog.csdn.net/lushuaiyin/article/details/7017662
		 */
		ActionContext actionContext = ActionContext.getContext();
		HttpServletRequest request=  (HttpServletRequest)actionContext.get(ServletActionContext. HTTP_REQUEST); 
		Map session= (Map) actionContext.get(ServletActionContext.SESSION);  



		SysSqlLogInfoWrapper sysSqlLogInfoWrapper = new SysSqlLogInfoWrapper();
		sysSqlLogInfoWrapper.setContextPath(request.getContextPath());		
		sysSqlLogInfoWrapper.setRequestUri(request.getRequestURI());		
		sysSqlLogInfoWrapper.setServerName(request.getServerName());		
		sysSqlLogInfoWrapper.setServerPort(String.valueOf(request.getServerPort()));
		sysSqlLogInfoWrapper.setServletPath(request.getServletPath());
		sysSqlLogInfoWrapper.setRequestUrl(request.getRequestURL().toString());

		session.put("sysSqlLogInfo", sysSqlLogInfoWrapper);

		//								System.out.println("request.getAuthType()="+request.getAuthType());
		//								System.out.println("request.getCharacterEncoding()="+request.getCharacterEncoding());
		//								System.out.println("request.getContentLength()="+request.getContentLength());
		//								System.out.println("request.getContentType()="+request.getContentType());
		//								System.out.println("request.getContextPath()="+request.getContextPath());
		//								System.out.println("request.getLocalAddr()="+request.getLocalAddr());
		//								System.out.println("request.getLocalName()="+request.getLocalName());
		//								System.out.println("request.getLocalPort()="+request.getLocalPort());
		//								System.out.println("request.getMethod()="+request.getMethod());
		//								System.out.println("request.getPathInfo()="+request.getPathInfo());
		//								System.out.println("request.getPathTranslated()="+request.getPathTranslated());
		//								System.out.println("request.getProtocol()="+request.getProtocol());
		//								System.out.println("request.getQueryString()="+request.getQueryString());
		//								System.out.println("request.getRemoteAddr()="+request.getRemoteAddr());
		//								System.out.println("request.getRemoteHost()="+request.getRemoteHost());
		//								System.out.println("request.getRemotePort()="+request.getRemotePort());
		//								System.out.println("request.getRemoteUser()="+request.getRemoteUser());
		//								System.out.println("request.getRequestedSessionId()="+request.getRequestedSessionId());
		//								System.out.println("request.getRequestURI()="+request.getRequestURI());
		//								System.out.println("request.getScheme()="+request.getScheme());
		//								System.out.println("request.getServerName()="+request.getServerName());
		//								System.out.println("request.getServerPort()="+request.getServerPort());
		//								System.out.println("request.getServletPath()="+request.getServletPath());
		//								System.out.println("request.getAsyncContext()="+request.getAsyncContext());
		//								System.out.println("request.getAttributeNames()="+request.getAttributeNames());
		//								System.out.println("request.getCookies()="+request.getCookies());
		//								System.out.println("request.getDispatcherType()="+request.getDispatcherType());
		//								System.out.println("request.getHeaderNames()="+request.getHeaderNames());
		//								System.out.println("request.getInputStream()="+request.getInputStream());
		//								System.out.println("request.getLocale()="+request.getLocale());
		//								System.out.println("request.getLocales()="+request.getLocales());
		//								System.out.println("request.getParameterMap()="+request.getParameterMap());
		//								System.out.println("request.getParameterNames()="+request.getParameterNames());
		//								System.out.println("request.getParts()="+request.getParts());
		//								System.out.println("request.getRequestURL()="+request.getRequestURL());
		//								System.out.println("request.getServletContext()="+request.getServletContext());
		//								System.out.println("request.getSession()="+request.getSession());
		//								System.out.println("request.getUserPrincipal()="+request.getUserPrincipal());

		/*
		 * 目前有記入Wrapper
		 * request.getContextPath()=/BasicProject
		 * request.getRequestURI()=/BasicProject/systemParameterQuery.action
		 * request.getServerName()=localhost
		 * request.getServerPort()=8080
		 * request.getServletPath()=/systemParameterQuery.action
		 * request.getRequestURL()=http://localhost:8080/BasicProject/systemParameterQuery.action
		 * 
		 * request中，可取得之資料
		 * request.getAuthType()=null
		 * request.getCharacterEncoding()=UTF-8
		 * request.getContentLength()=43
		 * request.getContentType()=application/x-www-form-urlencoded
		 * request.getContextPath()=/BasicProject
		 * request.getLocalAddr()=0.0.0.0
		 * request.getLocalName()=0.0.0.0
		 * request.getLocalPort()=8080
		 * request.getMethod()=POST
		 * request.getPathInfo()=null
		 * request.getPathTranslated()=null
		 * request.getProtocol()=HTTP/1.1
		 * request.getQueryString()=null
		 * request.getRemoteAddr()=0:0:0:0:0:0:0:1
		 * request.getRemoteHost()=0:0:0:0:0:0:0:1
		 * request.getRemotePort()=49402
		 * request.getRemoteUser()=null
		 * request.getRequestedSessionId()=2A2F4D09AA4C921E882C767C81363E89
		 * request.getRequestURI()=/BasicProject/systemParameterQuery.action
		 * request.getScheme()=http
		 * request.getServerName()=localhost
		 * request.getServerPort()=8080
		 * request.getServletPath()=/systemParameterQuery.action
		 * request.getAsyncContext()=null
		 * request.getAttributeNames()=org.apache.catalina.util.Enumerator@1ac1e22
		 * request.getCookies()=[Ljavax.servlet.http.Cookie;@a826da
		 * request.getDispatcherType()=REQUEST
		 * request.getHeaderNames()=org.apache.tomcat.util.http.NamesEnumerator@e496ab
		 * request.getInputStream()=org.apache.catalina.connector.CoyoteInputStream@15fc672
		 * request.getLocale()=zh_TW
		 * request.getLocales()=org.apache.catalina.util.Enumerator@dd8e0d
		 * request.getParameterMap()={maintainType=[Ljava.lang.String;@1991de1, parameterCode=[Ljava.lang.String;@178aae1, parameterName=[Ljava.lang.String;@11abd68}
		 * request.getParameterNames()=java.util.Hashtable$Enumerator@8932e8
		 * request.getParts()=[]
		 * request.getRequestURL()=http://localhost:8080/BasicProject/systemParameterQuery.action
		 * request.getServletContext()=org.apache.catalina.core.ApplicationContextFacade@c08593
		 * request.getSession()=org.apache.catalina.session.StandardSessionFacade@181b3d4
		 * request.getUserPrincipal()=null
		 */

	}

}
